using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace MTRC.ODMS.Web.SOM.CodeSetup
{
    /// <summary>
    /// Author: XiaoChunhu
    /// </summary>
    public partial class CleanEstablishmentList : BasePage_SOM
    {
        #region MenuID

        protected override string MenuID
        {
            get
            {
                return "M140810";//set the Menu
            }
        }

        #endregion

        #region Page Init And Load

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(SetLanguage_Click);//use function to set the language
        }

        #endregion

        #region page load and set the page lanuage

        //when the page load,these funtion will be run
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grvData.PageSize = this.GridViewPageDefaultSize();
                SetLanguage();
            }
        }

        /// <summary>
        /// set the lanuage for the page
        /// </summary>
        private void SetLanguage()
        {
            this.lblLocation.Text = this.GetLabel("COM_Station", true);
            this.lblShift.Text = this.GetLabel("SOM_CleanShift", true);
            this.btnSearch.Text = this.GetLabel("COM_Search");
            this.btnAddNew.Text = this.GetLabel("SOM_AddNewAssetLoanItem");
            this.lblObsolete.Text = GetLabel("COM_Show", true);
            this.chkVoid.Text = this.GetLabel("SOM_Voided");
            BindShift();//when the page load, this funtion will to bind some data on the Shift
            BindLocation();//when the page load, this funtion will to bind some data on the Location
            BindData();//when the page load, this funtion will to bind some data on the grvData
        }

        //when you chanage the language,this function will be run
        void SetLanguage_Click(object sender, EventArgs e)
        {
            SetLanguage();
        }

        #endregion

        #region bind some data on the page 

        /// <summary>
        /// get the shift and bind on the control
        /// </summary>
        private void BindShift()
        {
            //get the shift code by the LangCode
            DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDCleanShift.GetShift(this.LangCode,0,0);
            BindListControl(this.ddlShift, "CleanShiftID", "ShiftCode", dt, true);//bind data for the control
            dt.Dispose();
            dt = null;
        }

        /// <summary>
        /// get the location and bind on the control
        /// </summary>
        private void BindLocation()
        {
            //get the location code by the LangCode
            DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDLocation.GetLocation(this.LangCode);
            BindListControl(this.ddlLocation, "LocationID", "LocationCode", dt, true);//bind data for the control
            dt.Dispose();
            dt = null;

            //added by huangyao 20081024
            if (DAL.Security.User.CanFunctionItemAccess("M140810_F1", this.ODMUser.UserProfileID, this.MenuID))
            {
                this.ddlLocation.Enabled = true;
            }
            else
            {
                this.ddlLocation.Enabled = false;
                //this.FindByValueAndSelect(this.ddlLocation, this.ODMUser.StationID.ToString());  //
                this.FindByValueAndSelect(this.ddlLocation, this.ODMUser.LocationID.ToString());
            }
        }

        /// <summary>
        /// get the datatable and bind on the grvData
        /// </summary>
        private void BindData()
        {
            //get the datatable by the condition
            DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDCleanEstablishment.GetCleanMessage(this.LangCode, int.Parse(this.ddlShift.SelectedValue), int.Parse(this.ddlLocation.SelectedValue), chkVoid.Checked);
            this.grvData.DataSource = dt.DefaultView;//bind the data on the grvData
            this.grvData.DataBind();
            dt.Dispose();
            dt = null;
        }

        /// <summary>
        /// where you trun page,this function will be run 
        /// </summary>
        protected void grvData_NeedDataBind()
        {
            BindData();
        }

        /// <summary>
        /// click the rows and send some to the CleanEstablishmentEntry page
        /// </summary>
        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //click the rows and send CleanPassScoreid to the Edit page
                ((HyperLink)e.Row.Cells[6].FindControl("hypEdit")).NavigateUrl = "CleanEstablishmentEntry.aspx?CleanEstablishmentID=" + this.grvData.DataKeys[e.Row.RowIndex]["CleanEstablishmentID"].ToString();//click the rows and send CleanEstablishmentID to the CleanEstablishmentEntry page
                ((HyperLink)e.Row.Cells[6].FindControl("hypEdit")).ToolTip = this.GetLabel("SOM_CleanEdit");//get the message
                e.Row.Cells[3].Text = this.FormatDateTime(DateTime.Parse(e.Row.Cells[3].Text), false);//set this cell type is datetime
                e.Row.Cells[4].Text = this.FormatDateTime(DateTime.Parse(e.Row.Cells[4].Text), false);//set this cell type is datetime
            }
        }

        #endregion

        #region some event

        //when you want to find some data for you need,you can click the "Search"
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        //when you want to create new data,you can click the "Add New"
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("CleanEstablishmentEntry.aspx");
        }

        #endregion
    }
}
